package com.bjpowerrnode.streamTest;

import com.bjpowerrnode.streamTest1.pojo.User;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

public class ICollectGroupBy {
    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User("sxt1",20,1));
        users.add(new User("sxt2",21,2));
        users.add(new User("sxt3",22,3));
        users.add(new User("sxt4",23,4));
        users.add(new User("sxt5",24,1));
        users.add(new User("sxt6",25,1));

        Map<Integer, List<User>> collect = users.stream().collect(Collectors.groupingBy(User::getId));
        List<User> users1 = collect.get(1);
        users1.forEach(System.out::println);
        Map<Integer, List<Integer>> collect1 = users.stream()
                .collect(Collectors.groupingBy(User::getId, Collectors.mapping(User::getAge, Collectors.toList())));
        System.out.println(collect1);

    }
}
